package Fragment;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.zqm.neu612.R;

public class CollectionFragment extends BaseFragment {
    private TextView shop_collect;
    private TextView food_collect;
    private CollectShopFragment collectShopFragment;
    private CollectFoodFragment collectFoodFragment;
    private View view = null;
    public CollectionFragment(){

    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view = inflater.inflate(R.layout.fragment_collection,container,false);
        initViews();
        initEvents();
        return view;
    }
    @Override
    public void onResume() {
        super.onResume();
        if (collectShopFragment == null) {
            collectShopFragment =new CollectShopFragment();
            addFragment(collectShopFragment);
        } else {
            replaceFragment(collectShopFragment);
        }
    }
    public void initViews(){
        shop_collect = (TextView)view.findViewById(R.id.shop_collect);
        food_collect = (TextView)view.findViewById(R.id.food_collect);
        shop_collect.setSelected(true);
        shop_collect.setTextColor(getResources().getColor(R.color.cardview_dark_background));
        food_collect.setTextColor(getResources().getColor(R.color.cardview_shadow_start_color));
    }
    public void initEvents(){
        shop_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(collectShopFragment == null){
                    collectShopFragment = new CollectShopFragment();
                }
                replaceFragment(collectShopFragment);
                shop_collect.setSelected(true);
                food_collect.setSelected(false);
                shop_collect.setTextColor(getResources().getColor(R.color.cardview_dark_background));
                food_collect.setTextColor(getResources().getColor(R.color.cardview_shadow_start_color));
            }
        });
        food_collect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (collectFoodFragment == null) {
                    collectFoodFragment = new CollectFoodFragment();
                }
                replaceFragment(collectFoodFragment);
                food_collect.setSelected(true);
                shop_collect.setSelected(false);
                food_collect.setTextColor(getResources().getColor(R.color.cardview_dark_background));
                shop_collect.setTextColor(getResources().getColor(R.color.cardview_shadow_start_color));
            }
        });
    }
    }
